package cn.hznc.controller.permission;

import cn.hznc.aspect.BusinessType;
import cn.hznc.aspect.Log;
import cn.hznc.controller.service.permission.EmployeePermissionService;
import cn.hznc.domain.entity.EmployeeEntity;
import cn.hznc.domain.entity.EmployeePermissionEntity;
import cn.hznc.domain.entity.RolesEntity;
import cn.hznc.domain.request.permission.EmployeePermissionReq;
import cn.hznc.domain.request.permission.RolesPermissionReq;
import cn.hznc.domain.response.PageResult;
import cn.hznc.domain.response.ResponseBody;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/userPermisson")
public class EmployeePermissionController {

    @Resource
    private EmployeePermissionService employeePermissionService;

    /**
     * 根据用户查询
     * @param pageSize
     * @param pageNo
     * @param employeeName
     * @return
     */
    @RequestMapping(value = "/queryPageByEmployeeName", method = RequestMethod.GET)
    public ResponseBody<PageResult<EmployeePermissionEntity>> queryPageByEmployeeName(@RequestParam Integer pageSize,
                                                                                      @RequestParam Integer pageNo,
                                                                                      @RequestParam String employeeName) {
        return ResponseBody.success(employeePermissionService.queryPageByEmployeeName(pageSize,pageNo,employeeName));
    }

    /**
     * 根据用户id删除
     * @param userId
     * @return
     */
    @RequestMapping(value = "/deleteByUserId", method = RequestMethod.GET)
    @Log(title = "删除用户以及对应人员信息" , businessType = BusinessType.DELETE)
    public ResponseBody deleteEmployee(@RequestParam Integer userId) {
        return ResponseBody.success(employeePermissionService.deleteEmployeeByUserId(userId));
    }

    /**
     * 查询全部角色
     * @return
     */
    @RequestMapping(value = "/queryAllRoles", method = RequestMethod.GET)
    public ResponseBody<List<RolesEntity>> queryAllRoles() {
        return ResponseBody.success(employeePermissionService.queryAllRoles());
    }
    /**
     * 查询全部人员
     * @return
     */
    @RequestMapping(value = "/queryAllEmployee", method = RequestMethod.GET)
    public ResponseBody<List<EmployeeEntity>> queryAllEmployee() {
        return ResponseBody.success(employeePermissionService.queryAllEmployee());
    }

    /**
     * 人员修改
     * @param employeePermissionReq
     * @return
     */
    @RequestMapping(value = "/updateEmployee", method = RequestMethod.POST)
    @Log(title = "人员修改" , businessType = BusinessType.UPDATE)
    public ResponseBody updateEmployee(@RequestBody EmployeePermissionReq employeePermissionReq) {
        return ResponseBody.success(employeePermissionService.updateEmployee(employeePermissionReq));
    }

    /**
     * 密碼修改
     * @param id
     * @param password
     * @return
     */
    @RequestMapping(value = "/updatePassword", method = RequestMethod.GET)
    @Log(title = "修改账号密码" , businessType = BusinessType.UPDATE)
    public ResponseBody updatePassword(@RequestParam Integer id,
                                       @RequestParam String password) {
        return ResponseBody.success(employeePermissionService.updatePassword(id,password));
    }

    @RequestMapping(value = "/queryEmployeeInfo", method = RequestMethod.GET)
    public ResponseBody queryEmployeeInfo(@RequestParam Integer userId) {
        return ResponseBody.success(employeePermissionService.queryEmployeeInfo(userId));
    }
}
